package com.action;

import java.text.DecimalFormat;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.dao.TGoodsDAO;
import com.dao.TJinhuoDAO;
import com.model.TJinhuo;
import com.opensymphony.xwork2.ActionSupport;

public class jinhuoAction extends ActionSupport
{
	private Integer id;
	private Integer goods_id;
	private Integer shuliang;
	private String danjia;
	
	private String zongjia;
	private String shijian;

	private TJinhuoDAO jinhuoDAO;
	private TGoodsDAO goodsDAO;
	
	
	public String jinhuoAdd()
	{
		TJinhuo jinhuo=new TJinhuo();
		
		jinhuo.setId(id);
		jinhuo.setGoods_id(goods_id);
		jinhuo.setShuliang(shuliang);
		jinhuo.setDanjia(danjia);
		
		jinhuo.setZongjia(zongjia);
		jinhuo.setShijian(shijian);
		
		double shuliang1=Double.parseDouble(shuliang.toString());
		double danjia1=Double.parseDouble(danjia.toString());
		double zongjia1=shuliang1 * danjia1;
		
		jinhuo.setZongjia(new DecimalFormat(".00").format(zongjia1));
		
		jinhuoDAO.save(jinhuo);
		
		HttpServletRequest req=ServletActionContext.getRequest();
		req.setAttribute("msg", "成功");
		return "msg";
	}
	
	
	
	public String jinhuoMana()
	{
		String sql="from TJinhuo where goods_id="+goods_id;
		List jinhuoList=jinhuoDAO.getHibernateTemplate().find(sql);
		for(int i=0;i<jinhuoList.size();i++)
		{
			TJinhuo jinhuo=(TJinhuo)jinhuoList.get(i);
		}
		HttpServletRequest req=ServletActionContext.getRequest();
		req.setAttribute("jinhuoList", jinhuoList);
		return ActionSupport.SUCCESS;
	}
	
	public String jinhuoDel()
	{
		TJinhuo jinhuo=jinhuoDAO.findById(id);
		jinhuoDAO.delete(jinhuo);
		
		HttpServletRequest req=ServletActionContext.getRequest();
		req.setAttribute("msg", "����ɹ�");
		return "msg";
	}



	public Integer getId() {
		return id;
	}



	public void setId(Integer id) {
		this.id = id;
	}



	public Integer getGoods_id() {
		return goods_id;
	}



	public void setGoods_id(Integer goods_id) {
		this.goods_id = goods_id;
	}



	public Integer getShuliang() {
		return shuliang;
	}



	public void setShuliang(Integer shuliang) {
		this.shuliang = shuliang;
	}



	public String getDanjia() {
		return danjia;
	}



	public void setDanjia(String danjia) {
		this.danjia = danjia;
	}



	public String getZongjia() {
		return zongjia;
	}



	public void setZongjia(String zongjia) {
		this.zongjia = zongjia;
	}



	public String getShijian() {
		return shijian;
	}



	public void setShijian(String shijian) {
		this.shijian = shijian;
	}



	public TJinhuoDAO getJinhuoDAO() {
		return jinhuoDAO;
	}



	public void setJinhuoDAO(TJinhuoDAO jinhuoDAO) {
		this.jinhuoDAO = jinhuoDAO;
	}



	public TGoodsDAO getGoodsDAO() {
		return goodsDAO;
	}



	public void setGoodsDAO(TGoodsDAO goodsDAO) {
		this.goodsDAO = goodsDAO;
	}

}
